﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using TheDrinksApp.Database;
using TheDrinksApp.Models;

namespace TheDrinksApp.Screen.Order
{
    public partial class GlassSizeScreen : UserControl
    {
        public MainPage parrent;
        private string sizeName;
        private bool isCheckIce = false;
        private bool isCheckLemon = false;
        public bool IsCheckLemon
        {
            get { return isCheckLemon; }
            set { isCheckLemon = value; }
        }

        public bool IsCheckIce
        {
            get { return isCheckIce; }
            set { isCheckIce = value; }
        }

        public GlassSizeScreen(MainPage _parrent)
        {
            InitializeComponent();
            parrent = _parrent;
        }
        private void gridSingle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            sizeName = "SINGLE";
            MixerChangeSize();
        }

        private void gridDouble_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            sizeName = "DOUBLE";
            MixerChangeSize();
        }

        private void gridTriple_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            sizeName = "TRIPLE";
            MixerChangeSize();
        }
        private void MixerChangeSize()
        {
            var imageBrushNonSelect = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri("/Resources/recentOrderItemBackground.png", UriKind.Relative))
            };
            var imageBrushSelected = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri("/Resources/sizeWithControls.png", UriKind.Relative))
            };
            gridDouble.Background = gridSingle.Background = gridTriple.Background = imageBrushNonSelect;
            if (sizeName.Equals("SINGLE"))
            {
                gridSingle.Background = imageBrushSelected;
            }
            else if (sizeName.Equals("DOUBLE"))
            {
                gridDouble.Background = imageBrushSelected;
            }
            else if (sizeName.Equals("TRIPLE"))
            {
                gridTriple.Background = imageBrushSelected;
            }
            Util.currentOrder.size = Util.GetSizeByName(sizeName);
        }
        private void toggleLemon_Checked(object sender, RoutedEventArgs e)
        {
            IsCheckLemon = true;
        }

        private void toggleLemon_Unchecked(object sender, RoutedEventArgs e)
        {
            IsCheckLemon = false;
        }

        private void toggleIce_Unchecked(object sender, RoutedEventArgs e)
        {
            IsCheckIce = false;
        }

        private void toggleIce_Checked(object sender, RoutedEventArgs e)
        {
            IsCheckIce =true;
        }

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            tbName.Text = Util.currentOrder.drink.DrinkName.ToUpper();
            sizeName = Util.currentOrder.size.SizeName.ToUpper();
            MixerChangeSize();
        }

        private void Image_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            CurrentOrderDAO current = new CurrentOrderDAO();
            current = Util.currentOrder;
            current.quantity = 1;
            current.ice = IsCheckIce;
            current.lemon = IsCheckLemon;
            Util.orderItems.Add(current);
            Util.AddToCurrentOrders();
            GlobalVariable.mainPage.ShowPage(PAGE.CURRENT_ORDER);
            //current.category = Util.currentOrder.category;
            //current.drink = Util.currentOrder.drink;
            //current.ice = IsCheckIce;
            //current.lemon = isCheckLemon;
            //current.mixer = Util.currentOrder.mixer;
            //current.quantity = 1;
            //current.size = Util.currentOrder.size;
        }
    }
}
